local sk__yinmeng = fk.CreateSkill {

  name = "sk__yinmeng",

  tags = {},

}



sk__yinmeng:addEffect("active", {
  name = "sk__yinmeng",
  anim_type = "support",
  card_num = 0,
  target_num = 1,
  prompt = "#sk__yinmeng",
  can_use = function(self, player)
    return not player:isKongcheng() and
    player:usedSkillTimes(sk__yinmeng.name, Player.HistoryPhase) < math.max(player:getLostHp(), 1)
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    local target = Fto_select
    return #selected == 0 and to_select ~= player and not target:isKongcheng() and
        (target.gender == General.Male or target.gender == General.Bigender)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local card1 = room:askForCardChosen(player, target, "h", sk__yinmeng.name, "#sk__yinmeng-choose::" .. target.id)
    local type1 = Fk:getCardById(card1).type
    target:showCards(card1)
    if player.dead or player:isKongcheng() then return end
    local card2 = room:askForCard(player, 1, 1, false, sk__yinmeng.name, false, ".", "#sk__yinmeng-show")
    local type2 = Fk:getCardById(card2[1]).type
    player:showCards(card2)
    if type1 == type2 then
      if not player.dead then
        player:drawCards(1, sk__yinmeng.name)
      end
      if not target.dead then
        target:drawCards(1, sk__yinmeng.name)
      end
    else
      if table.contains(target:getCardIds("h"), card1) then
        room:throwCard(card1, sk__yinmeng.name, target, player)
      end
    end
  end,
})

return sk__yinmeng
